package de.grosjohann.android.feuerwehr.service;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import de.grosjohann.android.feuerwehr.util.FileUtil;
import de.grosjohann.android.feuerwehr.webservice.CalendarWsFacade;

public class CalendarNotificationService
  extends IntentService {

  public static final String CALENDAR_DATA = "feuerwehr.CalendarData";

  private static final String NAME = "CalendarNotificationService";

  public CalendarNotificationService() {
    super(NAME);
  }

  @Override
  protected void onHandleIntent(Intent newIntent) {

    Log.d(NAME, "handle");

    Context context = getApplicationContext();

    try {
      String json = CalendarWsFacade.getCalendar(context);
      FileUtil.writeFile(context, CALENDAR_DATA, json);

    } catch (Exception ex) {
      Log.e(NAME, ex.getMessage(), ex);
    }
  }
}
